<div class="page-content" >
	<div class="panel panel-default">
		<div class="panel-heading">
			<ul class="breadcrumb">
				<li><a href="<{:U('Questions/exams')}>">试卷管理</a></li>
				<li><{$exam_type[$type]}></li>
			</ul>
		</div>
		<div class="panel-body">
			<form action="<{:U('Questions/add_exams')}>" method="post" class="form-horizontal">
				<fieldset>
					<input type="hidden" name="examid" value="<{$data.examid}>"/>
					<input type="hidden" name="examtype" value="<{$type}>"/>
					<div class="form-group">
						<label class="col-sm-2 control-label">试卷名称</label>
						<div class="col-sm-7">
							<input type="text" name="exam" class="form-control" value="<{$data.exam}>">
						</div>
						<div class="col-sm-3"> </div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">课程</label>
						<div class="col-sm-7">
							<select  onChange="exam_questype_set(this)" name="subjectid" id="examsubject"  class="combox input-medium" target="sectionselect" refurl="<{:U('Subject/get_ajax_section',array('type'=>'_sel'))}>?subjectid={value}" autocomplete="off">
								<option value="0">选择科目</option>
								<volist name="subject_list" id="vo"> <option 
									<if condition="$data['subjectid'] eq $vo['subjectid']">selected="selected"</if>
									  value="<{$vo.subjectid}>"><{$vo.subject}>
									</option>
								</volist>
							</select>
							<if condition="$type eq 'knows_exam' or $type eq 'module_exam'">
								<select name="sectionid" class="combox input-medium" id="sectionselect" target="knowsselect" refurl="<{:U('Subject/get_ajax_knows',array('type'=>'_sel'))}>?sectionid={value}" autocomplete="off">
									<option value="0">选择章节</option>
								</select>
							</if>
							<if condition="$type eq 'knows_exam'">
								<select name="knowsid"  id="knowsselect" class="input-medium" autocomplete="off">
									<option value="">选择知识点</option>
								</select>
							</if>
						</div>
						<div class="col-sm-3"> </div>
					</div>
					<div class="form-group" id="choicebox">
						<label class="col-sm-2 control-label">难度</label>
						<div class="col-sm-7">
							<select name="examlevel" class="input-medium" autocomplete="off">
								<option value="">难度不限</option>
								<volist name="questionlevel" id="vo"> <option 
									<if condition="$data['examlevel'] eq $key">selected="selected"</if>
									 value="<{$key}>"><{$vo}>
									</option>
								</volist>
							</select>
						</div>
						<div class="col-sm-3"> </div>
					</div>
					
					<!--<div class="form-group" id="choicebox">
		<label class="col-sm-2 control-label">评卷方式</label>
		<div class="col-sm-7">
			 <label class="radio inline">
				<input name="examdecide" type="radio" value="1" autocomplete="off">教师评卷
			</label>
			<label class="radio inline">
				<input name="examdecide" type="radio" value="0" checked="" autocomplete="off">学生自评
			</label>
			<span class="help-block">教师评卷时有主观题则需要教师在后台评分后才能显示分数，无主观题自动显示分数。</span>
				 
		</div>
		 <div class="col-sm-3">
		</div>
	</div>-->
					
					<div class="form-group" id="choicebox">
						<label class="col-sm-2 control-label">学分</label>
						<div class="col-sm-7">
							<input type="text" name="examsetting[xuebazi]" value="<{$data.examsetting.xuebazi}>" size="4" needle="needle" class="inline" autocomplete="off">
							<span class="help-block">作试卷获得学分</span> </div>
						<div class="col-sm-3"> </div>
					</div>
					<!--考试模块-->
					<if condition="$type eq 'selfpage'">
						<div class="form-group" id="choicebox">
							<label class="col-sm-2 control-label">考试时间</label>
							<div class="col-sm-7">
								<input type="text" name="examsetting[examtime]" value="<{$data.examsetting.examtime}>" size="4" needle="needle" class="inline" autocomplete="off">
								分钟 </div>
							<div class="col-sm-3"> </div>
						</div>
						<div class="form-group" id="choicebox">
							<label class="col-sm-2 control-label">试卷总分</label>
							<div class="col-sm-7">
								<input type="text" id="score" name="examsetting[score]" value="<{$data.examsetting.score}>"  size="4" needle="needle" class="inline" autocomplete="off">
							</div>
							<div class="col-sm-3"> </div>
						</div>
						<div class="form-group" id="choicebox">
							<label class="col-sm-2 control-label">及格线</label>
							<div class="col-sm-7">
								<input type="text" name="examsetting[passscore]" value="<{$data.examsetting.passscore}>" size="4" needle="needle" class="inline" autocomplete="off">
							</div>
							<div class="col-sm-3"> </div>
						</div>
					</if>
					<!--考试模块--> 
					<!--题型设置-->
					<div class="form-group sortable ui-sortable" id="set_exam_questype">
						<volist name="data['examsetting']['questype']"  id="vo">
							<div class="form-group" data="<{$vo.questype.questid}>" id="choicebox_<{$vo.questype.questid}>">
								<label class="col-sm-2 control-label"><{$vo.questype.questype}></label>
								<div class="col-sm-7">
									<div class="controls"> <span class="info">共&nbsp;</span>
										<input id="iselectallnumber_<{$vo.questype.questid}>" type="text" class="input-mini" needle="needle" name="examsetting[questype][<{$vo.questype.questid}>][number]"  onkeyup="check()" id="number_<{$vo.questype.questid}>" value="<{$vo.number}>" size="2" msg="您必须填写总题数" autocomplete="off">
										<span class="info">&nbsp;题，每题&nbsp;</span>
										<input class="input-mini" needle="needle" type="text" name="examsetting[questype][<{$vo.questype.questid}>][score]"  onkeyup="check()" id="score_<{$vo.questype.questid}>" value="<{$vo.score}>" size="2" msg="您必须填写每题的分值" autocomplete="off">
										<span class="info">&nbsp;分，描述&nbsp;</span>
										<input class="input-mini" type="text" name="examsetting[questype][<{$vo.questype.questid}>][describe]" onKeyUp="check()" value="<{$vo.describe}>" size="12" autocomplete="off">
										<if condition="$type neq 'autopage'"> <span class="info">&nbsp;已选题数：<a id="ialreadyselectnumber_<{$vo.questype.questid}>"><{$vo.questions_count}></a>&nbsp;&nbsp;题</span> <span class="info">&nbsp;<a class="btn btn-xs" href="javascript:;" onClick="show_examquestions(<{$vo.questype.questid}>)">看题</a></span> <span class="info">&nbsp;<a class="btn btn-xs" href="javascript:;" onClick="sel_examquestions(<{$vo.questype.questid}>)">选题</a></span>
											<else/>
											<span class="info">&nbsp;难度题数：易&nbsp;</span>
											<input class="input-mini" onKeyUp="check()" id="easynumber_<{$vo.questype.questid}>" type="text" name="examsetting[questype][<{$vo.questype.questid}>][easynumber]" value="<{$vo.easynumber}>" size="2"  autocomplete="off">
											<span class="info">&nbsp;中&nbsp;</span>
											<input class="input-mini" onKeyUp="check()" id="middlenumber_<{$vo.questype.questid}>" type="text" name="examsetting[questype][<{$vo.questype.questid}>][middlenumber]" value="<{$vo.middlenumber}>" size="2"  autocomplete="off">
											' <span class="info">&nbsp;难&nbsp;</span>
											<input class="input-mini" type="text" onKeyUp="check()" id="hardnumber_<{$vo.questype.questid}>" name="examsetting[questype][<{$vo.questype.questid}>][hardnumber]" value="<{$vo.hardnumber}>" size="2" autocomplete="off">
										</if>
										<input type="hidden" value="<{$vo.questions}>" id="iselectquestions_<{$vo.questype.questid}>" name="examsetting[questype][<{$vo.questype.questid}>][questions]" autocomplete="off">
									</div>
									<small class="help-block"></small> </div>
								<div class="col-sm-3"> </div>
							</div>
						</volist>
					</div>
					<!--题型结束-->
					
					<div class="control-group">
						<div class="col-sm-offset-2 col-sm-7">
							<button onClick="return check()" class="btn btn-primary" type="submit" autocomplete="off">提交</button>
						</div>
					</div>
				</fieldset>
			</form>
		</div>
	</div>
</div>

<!-- Modal -->
<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
				<h4 class="modal-title" id="myModalLabel">问题列表</h4>
			</div>
			<div class="modal-body" id="ajax_page_body"> </div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
</div>
<script>
var subject_set=<{$subject_set}>;
var examtype="<{$type}>";
</script> 
<script type="text/javascript">

function check(){
	var leng=$("#set_exam_questype .form-group").length;
	var has_error=0;
	var flag=0;
	if(leng>0){
			var score=Number($("#score").val());
			var number=0;
			var set_score=0;
			var key;
			$("#set_exam_questype .form-group").each(function(i,v){
				key=Number($(v).attr('data'));
				number=Number($("#iselectallnumber_"+key).val());
				set_score+=number*Number($("#score_"+key).val());
				/****随机组题***/
				if(examtype=="autopage"){
					set_number=Number($("#easynumber_"+key).val())+Number($("#middlenumber_"+key).val())+Number($("#hardnumber_"+key).val());
					if(set_number!=number){
						$(v).addClass("has-error");
						$(v).find(".help-block").eq("0").html("难度题量相加要与题量相等");
						flag=1;
					}else{
						$(v).removeClass("has-error").addClass("has-success");
						$(v).find(".help-block").eq("0").html("");
					}
				}
				/****手工组卷*******/
				if(examtype=="selfpage"){
					set_number=Number($("#ialreadyselectnumber_"+key).text());
					if(set_number!=number){
						$(v).addClass("has-error");
						$(v).find(".help-block").eq("0").html("已选择题数要与题量相等");
						flag=1;
					}else{
						$(v).removeClass("has-error").addClass("has-success");
						$(v).find(".help-block").eq("0").html("");
					}
				}
			})
			 if(set_score!=score && examtype=="selfpage"){
				$("#set_exam_questype").addClass("has-error");
				$("#choicebox_"+key).find(".help-block").eq("0").html("题型总分要与试卷总分相等");
				flag=1;
			 }else{
				$("#set_exam_questype").removeClass("has-error").addClass("has-success");
				$("#choicebox_"+key).find(".help-block").eq("0").html("");
			 }
			if(flag==1){
				return false;
			}else{
				$(".form-horizontal").data('bootstrapValidator').resetForm();
				return true;
			}
	}
 
}


$(function(){
    $(".form-horizontal").bootstrapValidator({
        message: '您填入的值不合法',
        fields:{
            exam: {
                message: '试卷名称',
                validators: {
                    notEmpty: {
                        message: '试卷名称不能为空'
                    },
                }
            },
			 examsubject: {
                message: '课程',
                validators: {
                    notEmpty: {
                        message: '请选择课程'
                    },  
                }
            },
			 questiontype: {
                message: '题型',
                validators: {
                    notEmpty: {
                        message: '请选择题型'
                    },  
                }
            },
			examlevel: {
                message: '难度',
                validators: {
                    notEmpty: {
                        message: '请选择难度'
                    },  
                }
			 },
			 'examsetting[examtime]': {
                message: '考试时间',
                validators: {
                    notEmpty: {
                        message: '考试时间不能为空'
                    },  
					greaterThan:{
                        value:0,
                        message: '考试时间不能小于0'
                    },
                }
			 },
			 'examsetting[score]': {
                message: '试卷总分',
                validators: {
                    notEmpty: {
                        message: '试卷总分不能为空'
                    },  
					greaterThan:{
                        value:0,
                        message: '试卷总分不能小于0'
                    },
                }
			 },
			 'examsetting[passscore]': {
                message: '及格线',
                validators: {
                    notEmpty: {
                        message: '及格线不能为空'
                    },  
					greaterThan:{
                        value:0,
                        message: '及格线分不能小于0'
                    },
                }
			 },
			 xuebazi: {
                message: '学分',
                validators: {
                    notEmpty: {
                        message: '学分不能为空'
                    },
					greaterThan:{
                        value:0,
                        message: '学分不能小于0'
                    },
                }
            },

        }
    });	
	<!--w修改的时候-->
<if condition="$data">	
	 add_vail();
 </if>
});

/*******手动加验证******/
function add_vail(){
	var id=$("#examsubject").val();
	var data=subject_set[id];
	$.each(data,function(i,v){
	var questid=v['questid'];
	/**********添加验证*****/
		$('.form-horizontal').bootstrapValidator('addField', 'examsetting[questype]['+questid+'][number]', {
				validators: {
					notEmpty: {
						message: v['questype']+'题量不能为空'
					},
					 greaterThan:{
                        value:0,
                        message: v['questype']+'题量不能小于0'
                    },
				}
        });
		$('.form-horizontal').bootstrapValidator('addField', 'examsetting[questype]['+questid+'][score]', {
				validators: {
					notEmpty: {
						message: v['questype']+'每题分数不能为空'
					},
					 greaterThan:{
                        value:0,
                        message: v['questype']+'每题分数不能小于0'
                    },
				}
        });
		$('.form-horizontal').bootstrapValidator('addField', 'examsetting[questype]['+questid+'][easynumber]', {
				validators: {
					notEmpty: {
						message: v['questype']+'易题量不能为空'
					},
					 greaterThan:{
                        value:0,
                        message: v['questype']+'易题量不能小于0'
                    },
				}
        });
		$('.form-horizontal').bootstrapValidator('addField', 'examsetting[questype]['+questid+'][middlenumber]', {
				validators: {
					notEmpty: {
						message: v['questype']+'中题量不能为空'
					},
					 greaterThan:{
                        value:0,
                        message: v['questype']+'中题量不能小于0'
                    },
				}
        });
		$('.form-horizontal').bootstrapValidator('addField', 'examsetting[questype]['+questid+'][hardnumber]', {
				validators: {
					notEmpty: {
						message: v['questype']+'难题量不能为空'
					},
					 greaterThan:{
                        value:0,
                        message: v['questype']+'难题量不能小于0'
                    },
				}
        });
		/**********添加验证结束*****/
	})
}
</script> 
<script type="text/javascript">
$(function(){
	 /********选中章节****/
	 <if condition="$data['subjectid']">
		 $.get("/Subject/get_ajax_section/type/_sel?subjectid=<{$data['subjectid']}>&questionsectionid=<{$data['sectionid']}>",function(data){
			$("#sectionselect").html(data);
		 })
	 </if>
	 /********知识点****/
	  <if condition="$data['sectionid']">
		 $.get("/Subject/get_ajax_knows/type/_sel?sectionid=<{$data['sectionid']}>&questionknowsid=<{$data['knowsid']}>",function(data){
			$("#knowsselect").html(data);
		 })
	 </if>
})
</script> 